package io.renren.modules.sys.service.impl;

import io.renren.common.utils.Constant;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.sys.dao.ReplenishmentDao;
import io.renren.modules.sys.entity.ReplenishmentEntity;
import io.renren.modules.sys.service.ReplenishmentService;


@Service("replenishmentService")
public class ReplenishmentServiceImpl extends ServiceImpl<ReplenishmentDao, ReplenishmentEntity> implements ReplenishmentService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String shelvesid = (String)params.get("shelvesid");
        String number = (String)params.get("number");
        String statu = (String)params.get("statu");
        String startime = (String)params.get("startime");
        String endtime = (String)params.get("endtime");
        String userid = (String)params.get("userid");
        IPage<ReplenishmentEntity> page = this.page(
                new Query<ReplenishmentEntity>().getPage(params),
                new QueryWrapper<ReplenishmentEntity>().like(StringUtils.isNotBlank(number),"number",number)
                        .eq(StringUtils.isNotBlank(shelvesid),"shelvesId",shelvesid)
                        .eq(StringUtils.isNotBlank(statu),"statu",statu)
                        .eq(StringUtils.isNotBlank(userid),"userId",userid)
                        .gt(StringUtils.isNotBlank(startime),"createtime",startime)
                        .lt(StringUtils.isNotBlank(endtime),"createtime",endtime)
                        .apply(params.get(Constant.SQL_FILTER) != null, (String)params.get(Constant.SQL_FILTER))
        );

        return new PageUtils(page);
    }

}
